package com.cykj.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author 王宇
 * @CreateTime: 2025-07-28  16:27
 * @BelongsProject: jd_seckill
 * @BelongsPackage: com.cykj.config
 * @description 过滤规则设置
 */
@Configuration
public class RedisRateConfig {
    @Bean
    public KeyResolver userKeyResolver() {
        KeyResolver keyResolver = new KeyResolver() {
            @Override
            public Mono<String> resolve(ServerWebExchange exchange) {
                // 写过滤规则，如可以根据ip地址进行过滤
                String ip = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
                System.out.println("ip: " + ip);
                return Mono.just(ip);
            }
        };
        return keyResolver;
    }
}
